package com.cskaoyan.service;

import com.cskaoyan.bean.WxFootprintListBean;
import com.cskaoyan.bean.WxFootprintVO;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.mapper.FootprintMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @USER: cuiweiguo#
 * @DATE: 2022/5/8
 * @TIME: 22:17
 * @PROJECT_NAME: mallproject2
 */
@Service
public class WxFootprintServiceImpl implements WxFootprintService {
    @Autowired
    FootprintMapper footprintMapper;

    @Override
    public WxFootprintListBean list(Integer userId, BaseParam baseParam) {
        //查询总共所有的数量
        Integer page = baseParam.getPage();//页码
        Integer limit = baseParam.getLimit();//数据量
        //分页插件 PageHelper，辅助我们做分页以及分页信息的获得
        PageHelper.startPage(page, limit);
        //执行查询过程中拼接分页信息
        //  username="%"+username+"%";

        List<WxFootprintVO> list = footprintMapper.wxListFootprintByUserId(userId);

        //total、pages、list
        //通过PageHelper帮我们来获得一些和分页相关的信息PageInfo

        PageInfo<WxFootprintVO> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        return WxFootprintListBean.data(total, pages, limit, page, list);


    }

    @Override
    public int delete(Integer id) {
        //逻辑删除
        int affectedRows = footprintMapper.updateDeleteFootprintById(id);
        if (affectedRows==1){
            return 200;
        }
        return 0;
    }
}
